﻿using UnityEngine;
using UnityEngine.UI;

namespace UnityView
{
    public static class UIConstant
    {
        // 点击响应距离
        public static float ClickThreshold = Screen.width / 50f;

        // 屏幕长宽比
        public static readonly float ScalingHeight = Screen.height / 1080f;
        public static readonly float ScalingWidth = Screen.width / 1920f;

        public static Vector2 Normalize(Vector2 v)
        {
            return new Vector2(v.x / ScalingWidth, v.y / ScalingHeight);
        }

        public static readonly float AspectRatio = Screen.height / (float)Screen.width;
        public static readonly float AntiAspectRatio = Screen.width / (float)Screen.height;

        /// <summary>
        /// sd, pivot, anchor_min, anchor_max
        /// </summary>
        public static readonly Vector2[] AnchorAlignmentVectors_Center =
            {new Vector2(1, 1), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f)};
        public static readonly Vector2[] AnchorAlignmentVectors_TopLeft =
            {new Vector2(1, -1), new Vector2(0, 1), new Vector2(0, 1), new Vector2(0, 1)};
        public static readonly Vector2[] AnchorAlignmentVectors_TopRight =
            {new Vector2(-1, -1), new Vector2(1, 1), new Vector2(1, 1), new Vector2(1, 1)};
        public static readonly Vector2[] AnchorAlignmentVectors_BottomLeft =
            {new Vector2(1, 1), new Vector2(0, 0), new Vector2(0, 0), new Vector2(0, 0)};
        public static readonly Vector2[] AnchorAlignmentVectors_BottomRight =
            {new Vector2(-1, 1), new Vector2(1, 0), new Vector2(1, 0), new Vector2(1, 0)};

        public static readonly Vector2[] AnchorAlignmentVectors_CentralTop =
            {new Vector2(1, -1), new Vector2(0.5f, 1), new Vector2(0.5f, 1), new Vector2(0.5f, 1)};
        public static readonly Vector2[] AnchorAlignmentVectors_CentralBottom =
            {new Vector2(1, 1), new Vector2(0.5f, 0), new Vector2(0.5f, 0), new Vector2(0.5f, 0)};
        public static readonly Vector2[] AnchorAlignmentVectors_CentralLeft =
            {new Vector2(1, -1), new Vector2(0, 0.5f), new Vector2(0, 0.5f), new Vector2(0, 0.5f)};
        public static readonly Vector2[] AnchorAlignmentVectors_CentralRight =
            {new Vector2(-1, 1), new Vector2(1, 0.5f), new Vector2(1, 0.5f), new Vector2(1, 0.5f)};

        public static readonly Vector2[] AnchorAlignmentVectors_MidLeft_Up =
            {new Vector2(1, 1), new Vector2(0, 0), new Vector2(0, 0.5f), new Vector2(0, 0.5f)};
        public static readonly Vector2[] AnchorAlignmentVectors_MidLeft_Down =
            {new Vector2(1, -1), new Vector2(0, 1), new Vector2(0, 0.5f), new Vector2(0, 0.5f)};
        public static readonly Vector2[] AnchorAlignmentVectors_MidRight_Up =
            {new Vector2(-1, 1), new Vector2(1, 0), new Vector2(1, 0.5f), new Vector2(1, 0.5f)};
        public static readonly Vector2[] AnchorAlignmentVectors_MidRight_Down =
            {new Vector2(-1, 1), new Vector2(1, 1), new Vector2(1, 0.5f), new Vector2(1, 0.5f)};
        public static readonly Vector2[] AnchorAlignmentVectors_MidTop_Left =
            {new Vector2(-1, -1), new Vector2(0, 1f), new Vector2(0.5f, 1f), new Vector2(0.5f, 1f)};
        public static readonly Vector2[] AnchorAlignmentVectors_MidTop_Right =
            {new Vector2(1, -1), new Vector2(0, 1f), new Vector2(0.5f, 1f), new Vector2(0.5f, 1f)};
        public static readonly Vector2[] AnchorAlignmentVectors_MidBottom_Left =
            {new Vector2(1, 1), new Vector2(0, 0), new Vector2(0.5f, 0), new Vector2(0.5f, 0)};
        public static readonly Vector2[] AnchorAlignmentVectors_MidBottom_Right =
            {new Vector2(1, 1), new Vector2(0, 0), new Vector2(0.5f, 0), new Vector2(0.5f, 0)};

        public const float AnimationDuration = 0.25f;

        public const int LayerDefault = 0;
        public const int LayerUI = 5;

        public static float AspectWidthToHeight(float aspect)
        {
            return aspect * AntiAspectRatio;
        }
        
        public static float AspectHeightToWidth(float aspect)
        {
            return aspect * AspectRatio;
        }

        public static float LengthWidthToHeight(float length)
        {
            return length * AspectRatio;
        }

        public static float LengthHeightToWidth(float length)
        {
            return length * AntiAspectRatio;
        }
        
        public const float DesignWidth = 1920f;
        public const float DesignHeight = 1080f;

        public static Font DefaultFont = FontData.defaultFontData.font;
        public static int DefaultFontSize = 32;
    }
}
